package com.csthink.web.infrastructure.mq.consumer;

import com.csthink.mq.payload.RocketMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 演示如何监听多tag {@link RocketMQListener}
 *
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-07
 */
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "group_rocketmq2",
        topic = "${async.mq.rocket.subscriber.topic.practice-practice}",
//        selectorExpression = ROCKETMQ_TAG_DELETE)
        selectorExpression = "update|delete")
//        selectorExpression = ROCKETMQ_TAG_UPDATE + "|" + ROCKETMQ_TAG_DELETE)
public class RocketMQ2Listener implements RocketMQListener<RocketMessage> {
    @Override
    public void onMessage(RocketMessage rocketMessage) {
        log.info("RocketMQ2Consumer Received msg: {}", rocketMessage);
        log.info("RocketMQ2Consumer Received operation: {}", rocketMessage.getOperation());
        log.info("RocketMQ2Consumer Received msg field: {}", rocketMessage.getLocalDateTime());
    }
}
